<!-- 修改系统设置检测项 -->
<div class="layuimini-main">
    <div class="layui-form layuimini-form" style="width:96%;">
		
		<!-- 隐藏ID -->
		<input type="hidden" name="repotId" />
        
		<div class="layui-form-item">
            <label class="layui-form-label required"> 项目代号 </label>
            <div class="layui-input-block">
				<input type="text" class="layui-input" name="medicalCode" lay-verify="medicalCode" lay-verify="required" />
			</div>
        </div>
		
		<div class="layui-form-item">
		    <label class="layui-form-label required"> 项目名称 </label>
		    <div class="layui-input-block">
		        <input type="text" class="layui-input" name="medicalName" lay-verify="medicalName" lay-verify="required" />
		    </div>
		</div>

		<div class="layui-form-item">
		    <label class="layui-form-label required"> 单位 </label>
		    <div class="layui-input-block">
		        <select name="medicalUnits" lay-filter="medicalUnits"></select>
		    </div>
		</div>
		
		<div class="layui-form-item">
		    <label class="layui-form-label required"> 参考值 </label>
		    <div class="layui-input-block">
				<input type="text" class="layui-input" name="medicalReference" lay-verify="required" lay-verify="medicalReference" />
		    </div>
		</div>
		
		<div class="layui-form-item">
		    <label class="layui-form-label required"> 检验方法 </label>
		    <div class="layui-input-block">
		        <select name="medicalMethod" lay-filter="medicalMethod"></select>
		    </div>
		</div>
		
		<!-- 区间 -->
		<div class="layui-form-item">
		    <label class="layui-form-label required"> 区间 </label>
		    <div class="layui-input-inline" style="width:300px;">
				<div class="layui-inline">
					<input type="text" class="layui-input" lay-verify="required" name="referemceLow" lay-verify="referemceLow" placeholder="最低值" style="width:90px;" />
				</div>
				<div class="layui-inline">
					<input type="text" class="layui-input" lay-verify="required" name="referemceHigh" lay-verify="referemceHigh" placeholder="最高值" style="width:90px;" />
				</div>
		    </div>
		</div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="save"> 保存 </button>
            </div>
        </div>
		
    </div>
</div>



<script src="lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="lib/jq-module/paigusu.min.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'layer', 'layarea'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
			layarea = layui.layarea,
            $ = layui.$;
		
        // 初始化表单，要加上，不然刷新部分组件可能会不加载
        //form.render();
		
        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
		
		//自定义验证规则
		form.verify({
			//第一种写法
		    medicalCode: function (value, item) {	//value控件值，item表单DOM对象
		        if (value.length == 0) {
		            return '项目代号不能为空';
		        }else if(value.length>16){
					return '项目代号不能超过16位'
				}
		    },
			medicalName: function (value, item) {	//value控件值，item表单DOM对象
			    if (value.length == 0) {
			        return '项目名称不能为空';
			    }else if(value.length>16){
					return '项目名称不能超过16位'
				}
			}
			//第二种写法
			// medicalCode: [/^[a-zA-Z0-9_-]{1,16}$/,''],
			// medicalName: [/^[a-zA-Z0-9_-]{1,16}$/, '密码必须在6~16位']
			//sex:[/^正则表达式$/, '弹出消息']
		});
		
		
        //监听保存按钮事件
        form.on('submit(save)', function(data) {
			//获得表单数据
			var formData = data.field;
			console.log('获得表单数据',formData);
		
			//处理表单数据
			// var postData = {
			// 	'menuId': formData.menuId,
			// 	'menuName': formData.menuName
			// }
			
			//通过ajax请求后端接口，并提交数据
			$.ajax({
				url : 'http://localhost:8006/sccMedicalReport',
				type: 'put',
				data: JSON.stringify(formData),
				contentType:'application/json;charset=UTF-8',
				success: function(result){	//后端响应成功回调函数
					console.log(result);
					//刷新页面
					table.reload('systemSettingId');
				},
				error:function(result){
					console.log(result);
					//刷新页面
					table.reload('systemSettingId');
				}
			});
			// //关闭弹出层
			layer.close(parentIndex);
            return false;
        });
    });
</script>